Skip to content

fix: improved contextual tuples layout for check/batch check#1223

Merged
aaguiarz merged 3 commits intomainfrom
fix/contextual-tuples-layout
Apr 3, 2026
Merged

fix: improved contextual tuples layout for check/batch check#1223
aaguiarz merged 3 commits intomainfrom
fix/contextual-tuples-layout

Conversation

@aaguiarz
Copy link
Copy Markdown
Member

@aaguiarz aaguiarz commented Apr 2, 2026

Description

What problem is being solved?

How is it being solved?

What changes are made to solve it?

In some languages contextual tuples were displayed as a single line, making them hard to read.

Before
image

** After**
image

References

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Summary by CodeRabbit

  • Documentation
    • Enhanced code snippet formatting in API documentation viewers for improved readability
    • Added proper indentation and multi-line structure to CURL and JavaScript SDK request examples

@aaguiarz aaguiarz requested review from a team as code owners April 2, 2026 11:02
Copilot AI review requested due to automatic review settings April 2, 2026 11:02
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6b5ecf54-8559-49cc-b3d4-68f459e567d4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Two snippet viewer components in the documentation were updated to reformat generated code examples. The CURL request body output was changed from single-line JSON to multi-line indented format. Additionally, the JS SDK code generation for contextual tuples was modified to use explicit object literal syntax instead of a direct JSON stringification approach.

Changes

Cohort / File(s) Summary
Snippet Viewer Formatting
src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx, src/components/Docs/SnippetViewer/CheckRequestViewer.tsx
Updated CURL request JSON output from single-line inline format to multi-line indented structure with proper newlines and spacing for contextual_tuples, context, and authorization_model_id fields. In CheckRequestViewer, also modified JS SDK code generation for contextualTuples to use explicit object literal array syntax with single-quoted field values instead of JSON stringification.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: improved contextual tuples layout for check/batch check' clearly and specifically describes the main change: improving how contextual tuples are laid out/formatted in the check and batch check request viewers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/contextual-tuples-layout

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-04-03 18:52 UTC

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves readability of generated documentation snippets by formatting contextual tuples across multiple lines for Check and BatchCheck request examples.

Changes:

  • Reformats the Check cURL request JSON payload to multi-line fields (including contextual tuples and context).
  • Reformats contextual tuples output for the Check JS SDK snippet.
  • Reformats the BatchCheck cURL request JSON payload’s contextual tuples and context sections.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/components/Docs/SnippetViewer/CheckRequestViewer.tsx Updates Check snippet rendering (cURL + JS SDK) to print contextual tuples in a more readable layout.
src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx Updates BatchCheck cURL snippet rendering to print contextual tuples in a more readable layout.
Comments suppressed due to low confidence (1)

src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx:416

  • The BatchCheck cURL snippet’s -d '{... payload is not valid JSON as generated: each check object ends with a trailing comma, and the checks array / root object are never closed before the snippet moves on to # Response. This makes the copied command unusable; consider building a request-body object and using JSON.stringify(body, null, 2) to render a correct, pretty-printed payload (like other viewers do).
      }${check.context ? `,\n      "context": ${JSON.stringify(check.context)}` : ''}
    },
  `,
    )
    .join('')}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx (1)

388-418: ⚠️ Potential issue | 🔴 Critical

Close the CURL payload and remove the JSON trailing commas.

This template still emits an invalid request body: the -d '{ block never closes before # Response, and the generated JSON keeps trailing commas in both tuple_key and the checks array items. The batch example will not run as written.

💡 Suggested fix
-  ${checks
-    .map(
-      (check) => `  {
+  ${checks
+    .map(
+      (check, index) => `  {
       "tuple_key": {
         "user":"${check.user}",
         "relation":"${check.relation}",
-        "object":"${check.object}",
-      },
+        "object":"${check.object}"
+      },
       "correlation_id": "${check.correlation_id}"${
         check.contextualTuples
           ? `,
       "contextual_tuples": {
         "tuple_keys": [${check.contextualTuples
               .map(
                 (tuple) => `
           {"user": "${tuple.user}", "relation": "${tuple.relation}", "object": "${tuple.object}"}`,
               )
               .join(',')}
         ]
       }`
           : ''
       }${check.context ? `,\n      "context": ${JSON.stringify(check.context)}` : ''}
-    },
+    }${index < checks.length - 1 ? ',' : ''}
   `,
     )
     .join('')}
+  ]
+}'
 
 # Response: 
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx` around lines
388 - 418, The generated curl JSON in BatchCheckRequestViewer.tsx is invalid:
fix the template that builds the -d payload (the multi-line template using
modelId and checks.map) by removing trailing commas inside each "tuple_key"
object and at the end of each check item, ensure the "checks" array items are
joined without leaving a trailing comma, properly serialize contextualTuples as
a JSON array (no trailing comma) and close the top-level JSON object and the
'-d' string (add the closing } and ending quote) so the final payload is valid
JSON.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/Docs/SnippetViewer/CheckRequestViewer.tsx`:
- Around line 109-115: The snippet in CheckRequestViewer.tsx currently
interpolates tuple.user/relation/object into single-quoted strings (the
contextualTuples rendering), which breaks on quotes/backslashes/newlines and
drops optional fields like condition; change the rendering to serialize each
tuple with JSON.stringify(tuple) (or a safe serializer) when building the
contextualTuples array so all properties (including condition) are preserved and
properly escaped, and keep the same join/indentation logic so the output matches
the SDK request shape.

---

Outside diff comments:
In `@src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx`:
- Around line 388-418: The generated curl JSON in BatchCheckRequestViewer.tsx is
invalid: fix the template that builds the -d payload (the multi-line template
using modelId and checks.map) by removing trailing commas inside each
"tuple_key" object and at the end of each check item, ensure the "checks" array
items are joined without leaving a trailing comma, properly serialize
contextualTuples as a JSON array (no trailing comma) and close the top-level
JSON object and the '-d' string (add the closing } and ending quote) so the
final payload is valid JSON.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7aea2e8f-4af5-4e96-8cf2-04d38f1a6561

📥 Commits

Reviewing files that changed from the base of the PR and between 0a4a612 and e2b6373.

📒 Files selected for processing (2)
  • src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx
  • src/components/Docs/SnippetViewer/CheckRequestViewer.tsx

dyeam0
dyeam0 previously approved these changes Apr 2, 2026
@aaguiarz aaguiarz merged commit 3d5721d into main Apr 3, 2026
14 checks passed
@aaguiarz aaguiarz deleted the fix/contextual-tuples-layout branch April 3, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants